package com.hnevc.androiduiclassone8;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String file="data.txt";
        String con="Hello tang hou hong";
        FileOutputStream fo;
        try{
            fo=openFileOutput(file,MODE_PRIVATE);
            fo.write(con.getBytes());
            fo.close();

        }catch(Exception e){
            e.printStackTrace();
        }
        FileInputStream fi;
        try {
            fi = openFileInput("data.txt");
            byte[] bu=new byte[fi.available()];
            fi.read(bu);
            con =new String(bu);
            fi.close();
        }  catch (IOException e) {
            e.printStackTrace();
        }


    }
}
